#!/bin/bash

# 验证 FrankaServo 包安装和功能的脚本

echo "🔍 验证 FrankaServo 包..."

# 1. 检查包是否已安装
echo "1. 检查包安装状态..."
if pip show frankaservo > /dev/null 2>&1; then
    echo "✅ 包已安装"
    pip show frankaservo | grep -E "(Name|Version|Location)"
else
    echo "❌ 包未安装"
    exit 1
fi

# 2. 测试基本导入
echo ""
echo "2. 测试基本导入..."
python3 -c "
try:
    import frankaservo
    print(f'✅ 成功导入 frankaservo，版本: {frankaservo.__version__}')
except ImportError as e:
    print(f'❌ 导入失败: {e}')
    exit(1)
"

# 3. 测试类导入
echo ""
echo "3. 测试类导入..."
python3 -c "
try:
    from frankaservo import FrankaPosServo
    print('✅ 成功导入 FrankaPosServo 类')
except ImportError as e:
    print(f'❌ 类导入失败: {e}')
    exit(1)
"

# 4. 测试数据类导入
echo ""
echo "4. 测试数据类导入..."
python3 -c "
try:
    from frankaservo.franka_pos_servo import CartesianCmd
    print('✅ 成功导入 CartesianCmd 数据类')
except ImportError as e:
    print(f'❌ 数据类导入失败: {e}')
    exit(1)
"

# 5. 检查命令行工具
echo ""
echo "5. 检查命令行工具..."
if command -v frankaservo-demo > /dev/null 2>&1; then
    echo "✅ frankaservo-demo 命令可用"
else
    echo "❌ frankaservo-demo 命令不可用"
fi

# 6. 测试基本功能（模拟，不需要真实机器人）
echo ""
echo "6. 测试基本功能（模拟）..."
python3 -c "
try:
    from frankaservo.franka_pos_servo import CartesianCmd
    from franky import Affine
    import numpy as np
    
    # 创建一个模拟的 Affine 对象
    position = Affine([0.1, 0.2, 0.3], quaternion=[1, 0, 0, 0])
    cmd = CartesianCmd(position=position, max_speed=0.01)
    
    print('✅ 基本功能测试通过')
except Exception as e:
    print(f'⚠️  基本功能测试失败（可能因为 franky 库未安装）: {e}')
"

echo ""
echo "🎉 验证完成！"
echo ""
echo "使用方法:"
echo "- 导入包: from frankaservo import FrankaPosServo"
echo "- 运行演示: frankaservo-demo"
echo "- 查看示例: examples/ 目录"
echo "- 运行测试: python -m pytest tests/"
